import {createSlice} from '@reduxjs/toolkit'
import { setLSMainColor, getLSMainColor } from '../localStorage'

const colorStore = createSlice({
     name: 'color',
     // 初始化state
     initialState: {
        mainColor: getLSMainColor() || '#1677ff'
     },
     // 修改状态的方法
     reducers: {
        setMainColor(state, action) {
            setLSMainColor(action.payload)
            state.mainColor = action.payload
        }
     }
})

// 解构出来actionCreater函数
const {setMainColor} = colorStore.actions
// 获取reducer
const reducer = colorStore.reducer
// 以按需导出的方式导出actionCreater
export { setMainColor }
// 以默认导出的方式导出reducer
export default reducer